<?php global $has_permit; ?>
    <form action="<?php echo site_url('admin/medical/object/index', true); ?>" method="post" id="frm_object_search">
    <?php if ($has_permit) :?>
    <div class="std_header auto_height">
        <div class="left">
            <strong><?php echo $module['title']; ?></strong>
        </div>
        <div class="right">
            <?php if ($has_privilege_new) :?>
            <button type="button" class="gray_btn" onclick="window.location='<?php echo site_url('admin/medical/object/edit', true); ?>'"><span>Thêm mới</span></button>
            <?php endif; ?>
        </div>
    </div>
    <div class="std_header auto_height search_header ">
        <div class="std" align="center">
            <table cellpadding="0" cellspacing="5" border="0">
                <tr>
                    <td>
                        <strong>Tên đối tượng</strong>
                    </td>
                    <td>
                        <input name="filters[name]"  type="text" class="std_input" value="<?php echo isset($filters['name']) ? $filters['name'] : ''; ?>" />
                    </td>

                    <td class="pdl_10">
                        <strong>Độ tuổi</strong>
                    </td>
                    <td>
                        <input name="filters[age_from]"  placeholder="Từ"  type="text" class="std_input" value="<?php echo isset($filters['age_from']) ? $filters['age_from'] : ''; ?>" /> -
                    </td>
                    <td>
                        <input name="filters[age_to]"  placeholder="Đến"  type="text" class="std_input" value="<?php echo isset($filters['age_to']) ? $filters['age_to'] : ''; ?>" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <strong>Giới tính</strong>
                    </td>
                    <td>
                        <select  name="filters[gender]"  placeholder="Tất cả" >
                            <option value="-1">Tất cả</option>
                            <option value="1" <?php if(isset($filters['gender']) && $filters['gender'] == 1):?> selected="selected" <?php endif ;?>>Nam</option>
                            <option value="2" <?php if(isset($filters['gender']) && $filters['gender'] == 2):?> selected="selected" <?php endif ;?> >Nữ</option>
                        </select>
                    </td>
                    <td>
                        <strong>Vị trí</strong>
                    </td>
                    <td>
                        <select  name="filters[pos_visible]"  placeholder="Tất cả" >
                            <option value="-1">Tất cả</option>
                            <option value="1" <?php if(isset($filters['pos_visible']) && $filters['pos_visible'] == 1):?> selected="selected" <?php endif ;?>>Toàn trang</option>
                            <option value="2" <?php if(isset($filters['pos_visible']) && $filters['pos_visible'] == 2):?> selected="selected" <?php endif ;?>>Admin</option>
                        </select>
                    </td>
                    <td>
                        <strong>Hiển thị</strong>&nbsp;&nbsp;
                        <select  name="filters[is_hidden]"  placeholder="Tất cả" >
                            <option value="-1">Tất cả</option>
                            <option value="1" <?php if(isset($filters['is_hidden']) && $filters['is_hidden'] == 1):?> selected="selected" <?php endif ;?>>Hiện</option>
                            <option value="2" <?php if(isset($filters['is_hidden']) && $filters['is_hidden'] == 2):?> selected="selected" <?php endif ;?>>Ẩn</option>
                        </select>
                    </td>
                </tr>
            </table>
        </div>
        <div class="std clearfix mt_10" align="center">
            <button type="button" class="gray_btn" onclick="return admin_medical_object.act_filter()">
                <span>Tìm kiếm</span>
            </button>
            &nbsp;
            <button type="button" class="gray_btn" onclick="return admin_medical_object.reset_filters('frm_object_search')">
                <span>Xóa lọc</span>
            </button>
        </div>
    </div>
    <div id="object_management">
        <?php if (count($collection) != 0) : ?>
        <?php $paginator = $this->load->view('medical/object/paginator', null, true); echo $paginator; ?>
        <?php endif; ?>
        <input type="hidden" name="current_page" id="current_page" value="<?php echo $current_page; ?>" />

        <?php $this->load->view('medical/object/message'); ?>
            <div class="block">
                <table class="gridview" width="100%" cellpadding="0" cellspacing="0" border="0">
                    <thead>
                    <tr>
                        <td><input id="check_all" type="checkbox" onclick="btn_util.check_all(this.checked, '.chk_id')" /></td>
                        <td><b>ID</b></td>
                        <td><b>Tên đối tượng</b></td>
                        <td><b>Tiền tố</b></td>
                        <td><b>Độ tuổi</b></td>
                        <td><b>Giới tính</b></td>
                        <td><b>Vị trí</b></td>
                        <td><b>Hiển thị</b></td>
                        <td><b>Thao tác</b></td>
                    </tr>
                    </thead>
                    <tbody>
                        <?php if (count($collection) != 0) : ?>
                        <?php foreach ($collection as $object) : ?>
                            <tr>
                                <input type="hidden" value="" class="edit_url" />
                                <td width="30px" valign="top">
                                    <input class="chk_id" type="checkbox" name="selected[]" value="<?php echo $object->id; ?>" />
                                </td>
                                <td width="30px" valign="top">
                                    <?php echo $object->id; ?>
                                </td>
                                <td valign="top">
                                    <strong><a <?php if ($has_privilege_view) :?>href="<?php echo site_url('admin/medical/object/edit/id/' . $object->id, true); ?>"<?php endif; ?>><?php echo $object->name; ?></a></strong>
                                </td>
                                <td width="60px" valign="top">
                                    <?php echo $object->title; ?>
                                </td>
                                <td width="120px" valign="top">
                                    <?php if ($object->unit == 1):?>
                                        <?php echo 'Từ '.$object->age_from.' - '.$object->age_to.' tuổi'; ?>
                                    <?php else :?>
                                        <?php echo 'Từ '.$object->age_from.' - '.$object->age_to.' tháng tuổi'; ?>
                                    <?php endif; ?>
                                </td>
                                <td valign="top">
                                    <?php if ($object->gender == 1) :?>
                                        <strong>Nam</strong>
                                    <?php else :?>
                                        <strong>Nữ</strong>
                                    <?php endif; ?>
                                </td>
                                <td valign="top">
                                    <?php if ($object->pos_visible == 1) :?>
                                    <strong>Toàn trang</strong>
                                    <?php else :?>
                                    <strong>Admin</strong>
                                    <?php endif; ?>
                                </td>
                                <td valign="top">
                                    <?php if ($object->is_hidden == 1) :?>
                                    <strong>Hiện</strong>
                                    <?php else :?>
                                    <strong style="color: red;">Ẩn</strong>
                                    <?php endif; ?>
                                </td>

                                <td valign="top">
                                    <p>
                                        <?php if ($has_privilege_view) :?>
                                        <a class="icon icon_edit" href="<?php echo site_url('admin/medical/object/edit/id/' . $object->id, true); ?>"></a>
                                        <?php endif; ?>
                                        <?php if ($has_privilege_delete) :?>
                                        <a class="icon icon_delete" href="<?php echo site_url('admin/medical/object/delete/id/' . $object->id, true); ?>" onclick="return confirm('Bạn muốn xóa chuyên mục này?')"></a>
                                        <?php endif; ?>
                                    </p>
                                </td>
                            </tr>
                        <?php endforeach; ?>

                        <?php else : ?>
                            <tr>
                                <td colspan="9" style="padding: 10px">
                                    <p align="center">Danh sách đối tượng rỗng trong thời điểm này hoặc truy vấn tìm kiếm không tìm thấy kết quả, <a href="<?php echo site_url('admin/medical/object/filtered_list/' . $return_url, true); ?>">Thử lại</a></p>
                                </td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                    <tfoot>

                    </tfoot>
                </table>
            </div>


        <?php if (count($collection) != 0) : ?>
        <?php $paginator = $this->load->view('medical/object/paginator', null, true); echo $paginator; ?>
        <?php endif; ?>

    </form>
    </div>
    <?php else :?>
        <?php $this->load->view('layouts/restricted'); ?>
    <?php endif; ?>

<div class="clearfix"></div>
<script type="text/javascript">
    $("#frm_object_edit").validate();
    function create_new(){
        $('#active_tab_edit a').trigger('click');
        $("#entity_id").val(0);
        $("#frm_object_edit input[type='text']").val("");
        $(".std_editor").text("");
    }
</script>
<script type="text/javascript" src="<?php echo BASE_URL; ?>js/admin/medical/object/function.js"></script>